<?php
namespace App\Models\Relations;

use Illuminate\Support\Facades\DB;
/**
 *
 * @author Joker
 *
 */
trait AdminTrait
{
    /**
     * 获取管理员列表
     */
    public function getAdminList($roles)
    {
        $roleids = array();
        foreach ($roles as $role)
            $roleids[] = $role->id;
        $result = DB::table('users')
                ->select('users.*','roles.name as rolesname','roles.display_name','roles.description')
                ->leftJoin('role_user','users.id','=','role_user.user_id')
                ->leftJoin('roles','roles.id','=','role_user.role_id')
                ->whereIn('roles.id',$roleids)
                ->paginate(20);
        return $result;
    }
    
    /**
     * 获取普通用户列表
     */
    public function getUsersList($roles)
    {
        $roleids = array();
        foreach ($roles as $role)
            $roleids[] = $role->id;
        $result = DB::table('users as u')
                  ->select('u.*','r.name as rolesname','r.display_name','r.description')
                  ->leftJoin('role_user as ru','u.id','=','ru.user_id')
                  ->leftJoin('roles as r','r.id','=','ru.role_id')
                  ->whereIn('r.id',$roleids)
                  ->paginate(20);
        return $result;
    }
    
}